package com.qf.dao.impl;

import com.qf.dao.OrderDao;
import com.qf.pojo.Order;
import com.qf.pojo.OrderItem;
import com.qf.utils.JdbcUtils;
import org.apache.commons.dbutils.QueryRunner;

import java.sql.SQLException;

public class OrderDaoImpl implements OrderDao {
    @Override
    public void insertOrder(Order order) throws SQLException {
        QueryRunner qr = new QueryRunner();
        String sql = "insert into orders values(?,?,?,?,?,?,?,?)" ;

        ///执行对象.update(Connnection 对象，sql,实际参数)
        int count = qr.update(JdbcUtils.getConnection(), sql,
                order.getOid(),
                order.getOrdertime(),
                order.getTotal(),
                order.getState(),
                order.getAddress(),
                order.getName(),
                order.getTelephone(),
                order.getUser().getUid());
        //测试一下.是否添加
        System.out.println(count);
    }

    @Override
    public void insertOrderItem(OrderItem orderItem) throws SQLException {
        QueryRunner qr = new QueryRunner();
        String sql  = "insert into orderitem values (?,?,?,?,?)";
        //执行对象执行sql
        int count = qr.update(JdbcUtils.getConnection(), sql, orderItem.getItemid(),
                orderItem.getCount(),
                orderItem.getSubtotal(),
                orderItem.getProduct().getPid(),
                orderItem.getOrder().getOid());
        //测试一下.是否拿到
        System.out.println(count);
    }

}
